package donnees;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.text.*;

public class Panier implements Serializable {
	private static final long serialVersionUID = 3793335329863587622L;
	
	private ArrayList<PanierItem> lesPanierItems;
	
	public Panier(){
		super();
		setLesPanierItems(new ArrayList<PanierItem>());
	}

	public void setLesPanierItems(ArrayList<PanierItem> lesPanierItems) {
		this.lesPanierItems = lesPanierItems;
	}

	public ArrayList<PanierItem> getLesPanierItems() {
		return lesPanierItems;
	}
	
	public String getPrixTotal(){
		float res=0.00f;
		Iterator<PanierItem> itPanier = lesPanierItems.iterator();
		while(itPanier.hasNext()){   
			PanierItem pi=itPanier.next();
			Produit prod=pi.getProd(); 
			res+=pi.getQuantite()*prod.getPrix();
		}
		return new DecimalFormat("###.00").format(res);
	}
	
	public int getDelaiTotal(){
	    int res=0;
		Iterator<PanierItem> itPanier = lesPanierItems.iterator();
		while(itPanier.hasNext()){   
			PanierItem pi=itPanier.next();
			Produit prod=pi.getProd(); 
			if(prod.getStock()>0){
				//si le client veut plus que le stock dispo, on donne le delaiHS
				if(pi.getQuantite()>prod.getStock()){
					res=prod.getDelaiHS();
				}
				if(prod.getDelaiES()>res){
					res=prod.getDelaiES();
				}
			}else{
				if(prod.getDelaiHS()>res){
					res=prod.getDelaiHS();
				}
			}
		}
		return res;
	}
}
